﻿package monitoring.resource;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;


public class ResourceManager {
    
    static ResourceManager _ResourceManager = new ResourceManager();
    
    private ResourceManager(){}
    
    private static final Map<String,ResourceDriver> resource_drivers = new ConcurrentHashMap<String,ResourceDriver>();   
    public static final String DEFAULT_DRIVER_NAME = "default"; 
    
    public static void registerDefaultPrivider(ResourceDriver d) {   
            System.out.println("ResourceDriver 등록");   
            registerDriver(DEFAULT_DRIVER_NAME, d);   
    }   
    
    public static void registerDriver(String name, ResourceDriver d) {   
        resource_drivers.put(name,d);   
    }
    
    public static Resource getResource() {   
            return getResource(DEFAULT_DRIVER_NAME);   
    }   
    
    public static Resource getResource(String name) {   
        ResourceDriver d = resource_drivers.get(name);   
            if(d==null)    
                   throw new IllegalArgumentException();   
            return d.getResource();   
    }
        
    public static ResourceManager getInstance(){
        if(_ResourceManager == null) _ResourceManager = new ResourceManager();
        return _ResourceManager;
    }
    
}
